More conversion on the time_t -> QDateTime effort. Most of the GPX path
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 7 Jul 2013 03:50:17 +0000 (03:50 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 7 Jul 2013 03:50:17 +0000 (03:50 +0000)
is "bigtime" safe now, I think.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4405 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/coastexp.cc
gpsbabel/defs.h
gpsbabel/gbdatetime.h [deleted file]
gpsbabel/glogbook.cc
gpsbabel/gpx.cc
gpsbabel/gtrnctr.cc
gpsbabel/kml.cc
gpsbabel/route.cc
gpsbabel/util.cc
gpsbabel/xmlgeneric.cc
gpsbabel/xmlgeneric.h

index 030ca04ea345ab263df475c372df787912980f5b..cadae77b93e27ed792a6c8c69352ba8f0f8024e4 100644 (file)
@@ -524,7 +524,9 @@ ce_wr_deinit(void)
 static char*
 ce_gen_creation_time(time_t tm)
 {
-  xml_fill_in_time(time_buffer, tm, XML_SHORT_TIME);
+  QDateTime qtm;
+  qtm = QDateTime::fromTime_t(tm);
+  xml_fill_in_time(time_buffer, qtm, XML_SHORT_TIME);
   return time_buffer;
 }
 
index a75af4bb51bd8d7bcc7fee002baa3cd1a3b33de6..c426f5a3e413625d8df9979703d590079e92d1fc 100644 (file)
@@ -275,7 +275,6 @@ class geocache_data {
     is_available(status_unknown),
     is_memberonly(status_unknown),
     has_customcoords(status_unknown),
-    exported(0),
     last_found(0),
     placer_id(0),
     favorite_points(0)
@@ -289,7 +288,7 @@ class geocache_data {
   status_type is_available:2;
   status_type is_memberonly:2;
   status_type has_customcoords:2;
-  time_t exported;
+  gpsbabel::DateTime  exported;
   time_t last_found;
   QString placer; /* Placer name */
   int placer_id; /* Placer id */
@@ -528,22 +527,15 @@ public:
   QString icon_descr;
 
   gpsbabel::DateTime  GetCreationTime() const {
-//QDateTime dt(creation_time);
-//qDebug() << dt.toString("dd.MM.yyyy hh:mm:ss.zzz");
-//fprintf(stderr, "ng %d\n", (int)creation_time);
    return creation_time;
-}
+  }
   void SetCreationTime(gpsbabel::DateTime t) { creation_time = t; 
-//qDebug() << t.toString("dd.MM.yyyy hh:mm:ss.zzz");
-//fprintf(stderr, "ns %d\n", (int)t);
-}
+  }
   void SetCreationTime(time_t t) { creation_time = t; 
-//fprintf(stderr, "t %d\n", (int)t);
-}
+  }
   void SetCreationTime(time_t t, int us) {
     creation_time = t; 
     microseconds = us;
-//fprintf(stderr, "t/us %d %d\n", (int)t, us);
   }
   gpsbabel::DateTime creation_time;
   int microseconds;    /* Optional millionths of a second. */
@@ -619,7 +611,7 @@ typedef struct {
   double       avg_hrt;        /* Avg Heartrate */
   double       avg_cad;        /* Avg Cadence */
   time_t       start;          /* Min time */
-  time_t       end;            /* Max time */
+  time_t        end;           /* Max time */
   int  min_hrt;        /* Min Heartrate */
   int  max_hrt;        /* Max Heartrate */
   int  max_cad;        /* Max Cadence */
@@ -996,7 +988,7 @@ char* strlower(char* src);
 signed int get_tz_offset(void);
 time_t mklocaltime(struct tm* t);
 time_t mkgmtime(struct tm* t);
-time_t current_time(void);
+gpsbabel::DateTime current_time(void);
 void dotnet_time_to_time_t(double dotnet, time_t* t, int* ms);
 signed int month_lookup(const char* m);
 const char* get_cache_icon(const waypoint* waypointp);
diff --git a/gpsbabel/gbdatetime.h b/gpsbabel/gbdatetime.h
deleted file mode 100644 (file)
index 6b56171..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright ME.   
-
-#include <QDateTime>
-
-// As this code began in C, we have several hundred places that set and
-// read creation_time as a time_t.  Provide some operator overloads to make
-// that less painful.
-class gbDateTime : public QDateTime {
-public:
-  operator const time_t() const {
-    return this->toTime_t();
-  }
-  const time_t& operator=(const time_t& t) {
-    this->setTime_t(t);
-  }
-};
-
-
index 698c997bdbe03c26cc3e78acb6c555be78f7a404..8e91cbc9e4feb949fcbd4ada12bc95e350c639b0 100644 (file)
@@ -96,7 +96,8 @@ glogbook_waypt_pr(const waypoint* wpt)
   }
   gbfprintf(ofd, "                </Position>\n");
   gbfprintf(ofd, "                ");
-  xml_write_time(ofd, wpt->GetCreationTime(), wpt->microseconds, "Time");
+  QDateTime dt = wpt->GetCreationTime();
+  xml_write_time(ofd, dt, "Time");
   gbfprintf(ofd, "            </Trackpoint>\n");
 }
 
index 594c9f2f78baa3d2c9478bf6042dd13e7194ff23..940efd97735cd7496950b5b8515f3195848a8ec7 100644 (file)
@@ -1886,8 +1886,6 @@ gpx_write_bounds(void)
 static void
 gpx_write(void)
 {
-  time_t now = 0;
-
   /* if an output version is not specified and an input version is
    * available use it, otherwise use the default.
    */
@@ -1951,7 +1949,7 @@ gpx_write(void)
     gpx_write_gdata(&gpx_global->urlname, "urlname");
   }
 
-  now = current_time();
+  gpsbabel::DateTime now = current_time();
   char time_string[64];
   xml_fill_in_time(time_string, now, XML_LONG_TIME);
   if (time_string[0]) {
index b41d072be6f26bcfddd39bdf13ca23a1a8446f32..ba9460472bb2f4bf96c176a0d2c4e9960ffb1ef8 100644 (file)
@@ -38,8 +38,8 @@ static char gtc_sportlist[MAX_SPORTS][16] = { "Biking", "Running", "MultiSport",
 static int gtc_sport = 0;
 static int gtc_course_flag;
 
-static time_t gtc_least_time;
-static time_t gtc_most_time;
+static gpsbabel::DateTime gtc_least_time;
+static gpsbabel::DateTime gtc_most_time;
 static double gtc_start_lat;
 static double gtc_start_long;
 static double gtc_end_lat;
index fc6ff8af37d199c7a68c4cd0c904814e0c39d642..cbc29ab5fc90c9807a95677c017d4426d2d6d931 100644 (file)
@@ -713,10 +713,10 @@ void kml_output_trkdescription(const route_head* header, computed_trkdata* td)
   }
   if (td->start && td->end) {
     char time_string[64];
-
-    xml_fill_in_time(time_string, td->start, XML_LONG_TIME);
+    // FIXME (robertl): this straddling of time and string types is killing me
+    xml_fill_in_time(time_string, QDateTime::fromTime_t(td->start), XML_LONG_TIME);
     kml_td(hwriter, "Start Time", QString(" %1 ").arg(time_string));
-    xml_fill_in_time(time_string, td->end, XML_LONG_TIME);
+    xml_fill_in_time(time_string, QDateTime::fromTime_t(td->end), XML_LONG_TIME);
     kml_td(hwriter, "End Time", QString(" %1 ").arg(time_string));
   }
 
@@ -732,9 +732,10 @@ void kml_output_trkdescription(const route_head* header, computed_trkdata* td)
   if (td->start && td->end) {
     char time_string[64];
     writer->writeStartElement("TimeSpan");
-    xml_fill_in_time(time_string, td->start, XML_LONG_TIME);
+    // FIXME (robertl): this straddling of time and string types is gross
+    xml_fill_in_time(time_string, QDateTime::fromTime_t(td->start), XML_LONG_TIME);
     writer->writeTextElement("begin", time_string);
-    xml_fill_in_time(time_string, td->end, XML_LONG_TIME);
+    xml_fill_in_time(time_string, QDateTime::fromTime_t(td->end), XML_LONG_TIME);
     writer->writeTextElement("end", time_string);
     writer->writeEndElement(); // Close TimeSpan tag
   }
@@ -1849,7 +1850,7 @@ void kml_write_AbstractView(void)
     }
     if (kml_time_max) {
       char time_string[64];
-      time_t time_max;
+      gpsbabel::DateTime time_max;
       // In realtime tracking mode, we fudge the end time by a few minutes
       // to ensure that the freshest data (our current location) is contained
       // within the timespan.   Earth's time may not match the GPS because
index 607f74c3cc4257f35d5459d6d29ee71ab309cbe5..939914967527435ec7085ab5f0a3f1cf5f645799 100644 (file)
@@ -578,7 +578,7 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap)
   tdata->max_alt =  unknown_alt;
 
   QUEUE_FOR_EACH((queue *)&trk->waypoint_list, elem, tmp) {
-    time_t timed;
+    gpsbabel::DateTime timed;
     double tlat, tlon, plat, plon, dist;
 
     thisw = (waypoint *)elem;
index 998446fbe9a2b3103894e1da1e6efd0b8d64b856..3ad7ddf13641a4725c9417805cf66bad79f2343a 100644 (file)
@@ -882,16 +882,20 @@ mklocaltime(struct tm *t)
 }
 
 /*
- * A wrapper for time(2) that allows us to "freeze" time for testing.
+ * Historically, when we were C, this was A wrapper for time(2) that 
+ * allowed us to "freeze" time for testing. The UNIX epoch 
+ * (1970-1-1-00:00:00UTC) was a convenient value for that.  Now in the
+ * world of Qt, sub-second time is convenient, but regenerating all the
+ * reference files would be tedious, so we uphold that convention.
  */
-time_t
+gpsbabel::DateTime
 current_time(void)
 {
   if (getenv("GPSBABEL_FREEZE_TIME")) {
-    return 0;
+    return QDateTime::fromTime_t(0);
   }
 
-  return time(NULL);
+  return QDateTime::currentDateTime();
 }
 
 /*
index 80a863de1a28711408aa1c3124c2f0f4ccb41843..50f71bd18889c52f0e3573b8fe24f20ac063aaf3 100644 (file)
@@ -108,9 +108,9 @@ write_xml_entity_end(gbfile *ofd, const QString& indent,
 }
 
 void
-xml_fill_in_time(char *time_string, const time_t timep, int long_or_short)
+xml_fill_in_time(char *time_string, const gpsbabel::DateTime datetime, int long_or_short)
 {
-  QDateTime dt = QDateTime::fromTime_t(timep);
+  QDateTime dt = datetime;
   dt = dt.toUTC();
 
   const char* format;
@@ -128,10 +128,10 @@ abort();
 }
 
 void
-xml_write_time(gbfile *ofd, const time_t timep, int microseconds, const char *elname)
+xml_write_time(gbfile *ofd, gpsbabel::DateTime dt, const char *elname)
 {
   char time_string[64];
-  xml_fill_in_time(time_string, timep, XML_LONG_TIME);
+  xml_fill_in_time(time_string, dt, XML_LONG_TIME);
   if (time_string[0]) {
     gbfprintf(ofd, "<%s>%s</%s>\n",
               elname,
index f299ba5137d949ae7180710f929103696559a301..185a753f838be768d20f4a64001bcb3643773843 100644 (file)
@@ -51,8 +51,8 @@ void write_xml_entity_end(gbfile* ofd, const QString& indent, const QString& tag
 
 void write_optional_xml_entity(gbfile* ofd, const QString& indent,
                                const QString& tag, const QString& value);
-void xml_write_time(gbfile* ofd, const time_t timep, int microseconds, const char* elname);
-void xml_fill_in_time(char* time_string, const time_t timep, int long_or_short);
+void xml_write_time(gbfile* ofd, gpsbabel::DateTime time, const char* elname);
+void xml_fill_in_time(char* time_string, const gpsbabel::DateTime timep, int long_or_short);
 void write_xml_header(gbfile* ofd);
 void xml_ignore_tags(const char** taglist);